package monster.comm.action;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import monster.comm.log.ILog;
import monster.comm.log.LogService;
import monster.comm.util.ReturnVO;
import monster.comm.util.SessionBean;
import monster.comm.util.SysConstant;
import monster.comm.util.ReturnConstant;

/**
 * json访问基类，所有子类方法访问前必须调用isLogin方法判断
 * 是否登录，登录成功返回1，否返回0
 * @author wanghong 2012-12-24 BaseJsonAction.java
 * 
 */
public class BaseJsonAction extends ActionSupport {
	private static final long serialVersionUID = 3899277440076107376L;
	private static ILog log = LogService.getLog(BaseJsonAction.class);
	private String logined = "0";// 是否登录
	public  ReturnVO returnVO=new ReturnVO();//返回页面vo，子类方法应该设置此VO的值
	protected String getLogined() {
		return logined;
	}
	public ReturnVO getReturnVO(){
		   return returnVO;
	   }
	private HttpSession session;

	public BaseJsonAction() {
		session = ServletActionContext.getRequest().getSession(false);
	}
	/**
	 * 子类方法应该首先调用此方法
	 * 登录成功返回1，否则返回0
	 * @return String
	 */
	public String isLogin() {
		// String logined="0";//是否登录		
		Object obj = (session!=null?session.getAttribute(SysConstant.SESSION_NAME):null);
		if (obj == null) {// 没有登录			
			logined = "0";
		} else {
			logined = "1";
		}
		return logined;
	}
    /**
     * 返回登录人员sessionBean
     * @return Object
     */
	protected SessionBean getUserSession() {
		return (SessionBean)(session!=null?session.getAttribute(SysConstant.SESSION_NAME):null);
	}
}
